package com.xique.park.controller.client;


import com.xique.common.core.utils.OrikaUtil;
import com.xique.common.core.utils.SecurityUtils;
import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.core.web.page.TableDataInfo;
import com.xique.common.log.annotation.Log;
import com.xique.common.log.enums.BusinessType;
import com.xique.common.security.annotation.PreAuthorize;
import com.xique.park.bean.domain.client.ParkClientLoginInfo;
import com.xique.park.bean.request.client.ClientLoginInfoListRequest;
import com.xique.park.service.service.IParkClientLoginInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 系统访问记录Controller
 *
 * @author caogq
 * @date 2021-07-20
 */
@RestController
@RequestMapping("/clientLoginInfo")
public class ParkClientLoginInfoController extends BaseController {

    @Autowired
    private IParkClientLoginInfoService parkClientLoginInfoService;

    /**
     * 查询系统访问记录列表
     */
    @PreAuthorize(hasPermi = "oms:parkClientLoginInfo:list")
    @PostMapping("/list/{parkId}")
    public TableDataInfo list(ParkClientLoginInfo parkClientLoginInfo) {
        startPage();
        List<ParkClientLoginInfo> list = parkClientLoginInfoService.selectParkClientLoginInfoList(parkClientLoginInfo);
        return getDataTable(list);
    }

    /**
     * 新增保存系统访问记录
     */
    @PreAuthorize(hasPermi = "oms:parkClientLoginInfo:add")
    @Log(title = "系统访问记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult addSave(ParkClientLoginInfo parkClientLoginInfo) {
        return toAjax(parkClientLoginInfoService.insertParkClientLoginInfo(parkClientLoginInfo));
    }

    /**
     * 修改保存系统访问记录
     */
    @PreAuthorize(hasPermi = "oms:parkClientLoginInfo:edit")
    @Log(title = "系统访问记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult editSave(ParkClientLoginInfo parkClientLoginInfo) {
        return toAjax(parkClientLoginInfoService.updateParkClientLoginInfo(parkClientLoginInfo));
    }

    /**
     * 删除系统访问记录
     */
    @PreAuthorize(hasPermi = "oms:parkClientLoginInfo:remove")
    @Log(title = "系统访问记录", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    public AjaxResult remove(String ids) {
        return toAjax(parkClientLoginInfoService.deleteParkClientLoginInfoByIds(ids));
    }

    /** =====================================================岗亭用户V1====================================================== **/


    /**
     * 查询系统访问记录列表
     */
    @PreAuthorize(hasPermi = "park:client:loginInfoList")
    @GetMapping("/v1/list")
    public AjaxResult listV1(ClientLoginInfoListRequest request) {
        request.setParkId(SecurityUtils.getParkId());
        ParkClientLoginInfo info = OrikaUtil.convert(request, ParkClientLoginInfo.class);
        startPage();
        List<ParkClientLoginInfo> list = parkClientLoginInfoService.selectParkClientLoginInfoList(info);
        return new AjaxResult(getDataTable(list));
    }
}
